<?php
// 首页
class IndexAction extends HomeAction 
{
	function menu(){
		$this->display();
	}
	
	function _before_menu(){
		$this->assign('menu', $this->menuNode());
	}
	
	/**
	 * 菜单列表
	 *
	 * @return unknown
	 */
	function menuNode(){
		$apps = $this->getAppsList();
		foreach ($apps as $key=>$app){
			$menu = $this->getMenuNode($app['app_id']);
			foreach ($menu as $k=>$m){
				$menu[$k]['url'] = U($app['app_name'].'://'.$m['node_name'].'/index');
			}
			$apps[$key]['menu'] = $menu;
		}
		return $apps;
	}
	
	/**
	 * 取得应用列表
	 *
	 * @return array
	 */
	function getAppsList(){
		if(S('apps_list')){
			return S('apps_list');
		}
		$app_list = M('apps')->field('app_id, app_name, app_title')->order('sort ASC, app_id DESC')->findAll();
		S('apps_list', $app_list);
		return $app_list;
	}
	
	/**
	 * 取得应用下的所有菜单节点列表
	 *
	 * @param int $app_id
	 * @return array
	 */
	function getMenuNode($app_id=0){
		if(S('node_list_'.$app_id)){
			return S('node_list_'.$app_id);
		}
		$node_list = M('node')->field('node_id,app_id,node_name,node_title')->where('parent_id=0 AND status=1 AND app_id='.$app_id)->order('sort ASC, node_id DESC')->findAll();
		S('node_list_'.$app_id, $node_list);
		return $node_list;
	}
}
?>